# -*- coding:UTF-8 -*-
from django.db import connection

def buffer_info(start,page_num):
    cursor = connection.cursor()
    cursor.execute("select count(*) from equipment_info where equipment_no in (select equipment_no from system_info where use_status=0)")
    countRes = cursor.fetchone()
    count = countRes[0]
    cursor.execute("select equipment_no,equipment_type,sys_ip_inner,server_room_id from equipment_info"
                   " where equipment_no in (select equipment_no from system_info where use_status=0)"
                   " order by equipment_no desc limit " + str(start) + "," + str(page_num))
    infoRes = cursor.fetchall()
    infoFinal = []
    for singleV in infoRes:
        dict = {}
        dict['equipment_no'] = singleV[0]
        dict['equipment_type'] = singleV[1]
        dict['sys_ip_inner'] = singleV[2]
        dict['server_room_id'] = singleV[3]
        infoFinal.append(dict)

    return {'count':count,'buffer_list':infoFinal}